package com.czk.shop.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.comon.czk.constant.ShopCode;
import com.comon.czk.entity.Result;
import com.comon.czk.exception.CastException;
import com.czk.api.ICouponService;
import com.czk.shop.mapper.TradeCouponMapper;
import com.czk.shop.pojo.TradeCoupon;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author:ChenZhangKun
 * @Date: 2020/9/18 22:05
 */
@Component
@Service(interfaceClass = ICouponService.class)
public class CouponServiceImpl implements ICouponService {
    @Autowired
    private TradeCouponMapper tradeCouponMapper;
    @Override
    public TradeCoupon findOne(Long couponId) {
        TradeCoupon tradeCoupon = tradeCouponMapper.selectByPrimaryKey(couponId);
        return tradeCoupon;
    }

    @Override
    public Result updateCouponStatus(TradeCoupon coupon) {
        if (coupon==null||coupon.getCouponId()==null){
            CastException.cast(ShopCode.SHOP_REQUEST_PARAMETER_VALID);
        }
        // 更新优惠券状态
        tradeCouponMapper.updateByPrimaryKey(coupon);
        return new Result(ShopCode.SHOP_SUCCESS.getSuccess(),ShopCode.SHOP_SUCCESS.getMessage());
    }
}
